<template>
    <div class="app-container">
        <uc-table url="admin/inMaintenanceCycle/getCyclePage" name="设备维保周期配置" ref="cycleTable" pageable table-border :search-form="searchForm">
            <template slot="searchForm">
                <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
                    <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
                </el-form>
            </template>
            <template slot="columns">
                <el-table-column prop="name" label="名称" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="cycle" label="维保周期" align="left" :show-overflow-tooltip="true">
                  <template slot-scope="scope">
                    {{statusFormat(scope)}}
                  </template>
                </el-table-column>
                <el-table-column prop="percent" label="完成百分比" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="described" label="描述" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!--编辑按钮-->
                        <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
                        <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
                        <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </template>
        </uc-table>
    </div>
</template>

<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteCycle} from "@/api/cycle";
export default {
    name: "cycle",
    components: {UcTable},
    data(){
        return{
          scycleOptions: [],
          searchForm: {
              type:0,
          },
          deleteLoading:false
        }
    },
  created() {
    this.getDicts("cycle_type").then(response => {
      this.scycleOptions = response.data.data;
    });
  },
  methods:{
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.scycleOptions, row.row.cycle);
    },
    handleSearch(){
        this.$refs.cycleTable.getTableData(1)
    },
    handleAdd(){
        this.$router.push("/sys/cycleEdit/0")
    },
    handleEdit(val){
        this.$router.push("/sys/cycleEdit/"+val.ucId)
    },
    handleDelete(val){
      this.$confirm('您确定要执行删除【'+val.name+'】这个设备维保周期信息吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
          this.deleteLoading = true
          deleteCycle(val.ucId).then(res=>{
            this.deleteLoading = false
            this.$notify.success({
              title: '成功',
              message: "删除设备维保周期信息成功"
            })
            this.handleSearch()
          }).catch(res=>{
            this.deleteLoading = false
            this.$notify.error({
              title: '失败',
              message: res.msg
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    handleInfo(val){
        this.$router.push("/sys/cycleInfo/"+val.ucId)
    }
  }
}
</script>

<style scoped>

</style>
